//app.js
import ajax from './utils/js/ajax.js'
import instance from './utils/js/request.js'
App({
  globalData: {
    ajax: ajax
  },
  onLaunch: function () {
    wx.setNavigationBarTitle({
      title: "唱豫剧",
    });
    this.getUserInfo()
    // 用code换token
    // wx.login({
    //   success: (res) => {
    //     if (res.code) {
    //       //发起网络请求
    //         ajax.get('/user/userLogin', { jsCode: res.code }).then(data => {
    //           wx.setStorageSync('token', data.data)
    //           this.getUserInfo()
    //         })
    //     } else {
    //       console.log("获取用户登录态失败！" + res.errMsg);
    //     }
    //   },
    // });
    // 获取手机系统信息
    wx.getSystemInfo({
      success: (res) => {
        // 手机系统状态栏高度
        wx.setStorageSync("statusBarHeight", res.statusBarHeight);
        const platform = res.platform;
        const menu = wx.getMenuButtonBoundingClientRect();
        // 导航栏高度
        platform === "android"
          ? wx.setStorageSync("navHeight", 48 + res.safeArea.top)
          : wx.setStorageSync("navHeight", 44 + res.safeArea.top);
        wx.setStorageSync("windowHeight", res.windowHeight);
        //menu为胶囊，判断是否能读到胶囊位置，读不到则用具体一般数值表示
        if (menu) {
          wx.setStorageSync("menu", menu);
          // 导航栏高度
          wx.setStorageSync(
            "navBarHeight",
            menu.height + (menu.top - res.statusBarHeight) * 2
          );
          // 状态栏加导航栏
          wx.setStorageSync(
            "navStatusBarHeight",
            res.statusBarHeight +
              menu.height +
              (menu.top - res.statusBarHeight) * 2
          );
        } else {
          wx.setStorageSync("menu", null);
          // 导航栏高度
          wx.setStorageSync("navBarHeight", platform === "android" ? 48 : 44);
          // 状态栏加导航栏
          wx.setStorageSync(
            "navStatusBarHeight",
            res.statusBarHeight + (platform === "android" ? 48 : 44)
          );
        }
      },
      fail(err) {
        console.log(err);
      },
    });
  },
  onShow() {
    if (this.audioDom.paused) {
      this.player.status = 2;
    }
  },
  onHide: function () {},
  getUserInfo(){
    ajax.get('/user/userInfo').then(data => {
      if(data.code == 0){
        console.log(data.data,'userInfo')
        wx.setStorageSync('userInfo', data.data)
      }
    })
  },
  player: {
    list: [],
    current_music: 0,
    mode: 0, // 0 单曲    1 顺序   2 随机
    status: 0, // 0 未播放  1 播放中   2 暂停中  3 已结束
    playbackRate: 1, // 倍速
    a_resource: "",
    i_resource: "",
    global_show: 0, // 全局显示  0 不显示 1 显示
    playing: {
      id: "",
      name: "",
      cover: "",
      url: "",
      singer: {
        avatar: "",
        name: "",
      },
      currentTime: 0,
      duration: 0,
      timeArr: [],
      lrcArr: [],
    },
    audioDom: wx.createInnerAudioContext()
  },
  audioDom: wx.createInnerAudioContext(),
  recorderManager: wx.getRecorderManager()
});
